package com.mz.mattress.admin.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.admin.api.req.MemberQueryReq;
import com.mz.mattress.admin.service.MemberService;

import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Member;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@RestController
@RequestMapping(Constants.ADMIN_PATH + "member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping(value = "list")
    public Result<IPage<Member>> list(MemberQueryReq req) {
        return memberService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Member> getById(@PathVariable Long id) {
        return memberService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Member member) {
        return memberService.add(member);
    }

    @PutMapping
    public Result update(@RequestBody Member member) {
        return memberService.updateById(member);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Long> ids) {
        return memberService.deleteByIds(ids);
    }

}
